﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using PacManPP.Managers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace PacManPP.Objects
{
    class PacMan : IObject
    {

        public PacMan() {

            startFrame = 1;
            maxFrame = 4;
            spirteSheetName = "objects";
            Position = new Vector2(GameManager.boardBegin.X, GameManager.boardBegin.Y);

            poistion.X = poistion.X + GameManager.scale / 2 - 2;
            poistion.Y = poistion.Y + GameManager.scale / 2 + 1;

        }

        public override void HandleInput(KeyboardState keyboardState)
        {
           

            int x = (int)poistion.X;
            int y = (int)poistion.Y;

            BoardManager.checkCollisionWithDot(poistion);

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                if (x - 10 >= (int)GameManager.boardBegin.X * GameManager.scale)
                {
                    if (BoardManager.checkCollisionWithMonster(new Vector2(x-1, y)) == false &&
                        BoardManager.checkCollisionWithWall(new Vector2(x-1, y)) == false
                        )
                    {
                        poistion.X--;
                        move = (int)Directions.Left;
                    } 
                }                                
            }

            if (keyboardState.IsKeyDown(Keys.Right))
            {
                if (x + 14 < ((int)GameManager.boardBegin.X * GameManager.scale + (int)GameManager.boardSize.X * GameManager.scale))
                {
                    if (BoardManager.checkCollisionWithMonster(new Vector2(x+1, y)) == false &&
                        BoardManager.checkCollisionWithWall(new Vector2(x+1, y)) == false
                        )
                    {
                        poistion.X++;
                        move = (int)Directions.Right;
                    }   
                }             
            }

            if (keyboardState.IsKeyDown(Keys.Up))
            {
                if (y - 14 >= (int)GameManager.boardBegin.Y * GameManager.scale)
                {
                    if (BoardManager.checkCollisionWithMonster(new Vector2(x, y - 1)) == false &&
                        BoardManager.checkCollisionWithWall(new Vector2(x, y-1)) == false
                        )
                    {
                        poistion.Y--; ;
                        move = (int)Directions.Up;
                    }     
                } 
            }

            if (keyboardState.IsKeyDown(Keys.Down))
            {

                if (y + 10 < ((int)GameManager.boardBegin.Y * GameManager.scale + (int)GameManager.boardSize.Y * GameManager.scale))
                {
                    if (BoardManager.checkCollisionWithMonster(new Vector2(x,y+1)) == false &&
                        BoardManager.checkCollisionWithWall(new Vector2(x,y+1)) == false
                        )
                    {
                        poistion.Y++;
                        move = (int)Directions.Down;
                    }               
                }
            }

            
        }        
    }
}
